Skip to content

fix: receive message type assumption on nullish values#1366

Merged
bbortt merged 1 commit intocitrusframework:mainfrom
postfinance:fix/message-type-assumption
Jul 18, 2025
Merged

fix: receive message type assumption on nullish values#1366
bbortt merged 1 commit intocitrusframework:mainfrom
postfinance:fix/message-type-assumption

Conversation

@bbortt
Copy link
Collaborator

@bbortt bbortt commented Jul 3, 2025

a too eager message type assumption using getPayload(String) on the message leads to null'is values not being thus. e.g. it's interpreted as XML instead of PLAINTEXT. occured during implementation of citrusframework/citrus-simulator#315.

@bbortt bbortt requested review from christophd and tschlat July 15, 2025 05:32
@bbortt bbortt added Type: Bug Prio: High State: Review If pull-request has been opened an is ready/in review java Pull requests that update java code labels Jul 15, 2025
}

var payload = message.getPayload(String.class);
var payload = isNull(message.getPayload()) && "null".equals(message.getPayload(String.class)) ? null : message.getPayload(String.class);
Copy link
Collaborator

@tschlat tschlat Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be done better? It is smelly. Having a "null" string here seems to be the issue. Can't this be solved earlier? My feeling is that message.getPayload(String.class) should never return "null" unless there is a payload which really resolves to "null"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem was something along the line of this: a JSON message with null'ish payload resolves to {} when calling Message#getPayload(String) - but of course it does not have an Object representation, because it is an empty object. it is not "effectively nullish". thus a check on Message#getPayload() is not sufficient. it is additionally required to make sure the String representation is also "null".

I've refactored the code a bit, moved this into a method with a comment. that should make it more clear.

I don't think it can be catched earlier on, respectively this would go to deep and change too much of "accepted behavior".

Copy link
Collaborator Author

@bbortt bbortt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've amended your remarks @tschlat! thanks.

a too eager message type assumption using `getPayload(String)` on the message leads to `null`'is values not being thus.
e.g. it's interpreted as `XML` instead of `PLAINTEXT`.
occured during implementation of citrusframework/citrus-simulator#315.
@bbortt bbortt force-pushed the fix/message-type-assumption branch from 186e281 to b03604d Compare July 15, 2025 18:55
@christophd
Copy link
Member

would it help to set the default message type to PLAINTEXT? I think XML as a default is a historic value and as you have mentioned there is always a default validator for PLAINTEXT available.

If it helps to simplify the checks we can change the default to PLAINTEXT. Otherwise I am also good with the solution provided as it is right now. Many thanks!

@bbortt
Copy link
Collaborator Author

bbortt commented Jul 18, 2025

phu, we've tried (@tschlat and me) but it goes quit deep.. I fell like that change would be too risky.

thanks for the review!

@bbortt bbortt merged commit 1dacba0 into citrusframework:main Jul 18, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update java code Prio: High State: Review If pull-request has been opened an is ready/in review Type: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants